package com.jcgyl.export.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.jcgyl.export.entity.TbInventoryBody;
import com.jcgyl.export.entity.TbInventoryHead;
import com.jcgyl.export.entity.Tborderhead;
import com.jcgyl.export.entity.Tborderlist;
import com.jcgyl.export.entity.Tbpayinfo;
import com.jcgyl.export.entity.Tbwaybill;
import com.jcgyl.export.model.MessageHead;
import com.jcgyl.export.model.PayMessageHeader;
import com.jcgyl.export.model.SystemConstants;
import com.jcgyl.export.model.inventory.InventoryBody;
import com.jcgyl.export.model.inventory.InventoryBodyDetail;
import com.jcgyl.export.model.inventory.InventoryBodyMaster;
import com.jcgyl.export.model.inventory.InventoryGoods;
import com.jcgyl.export.model.inventory.InventoryXmlModel;
import com.jcgyl.export.model.order.ORDERLIST;
import com.jcgyl.export.model.order.OrderBody;
import com.jcgyl.export.model.order.OrderBodyDetail;
import com.jcgyl.export.model.order.OrderBodyMaster;
import com.jcgyl.export.model.order.OrderXmlModel;
import com.jcgyl.export.model.payinfo.PayBody;
import com.jcgyl.export.model.payinfo.PayBodyMaster;
import com.jcgyl.export.model.payinfo.PayXmlModel;
import com.jcgyl.export.model.waybill.WaybillBody;
import com.jcgyl.export.model.waybill.WaybillBodyMaster;
import com.jcgyl.export.model.waybill.WaybillXmlModel;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;

/*
 *  生成三单报文
 * 
 * 
 */
public class MessageHelper {
	private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式

	public static String replaceBlank(String str) {
		String dest = "";
		if (str != null) {
			Pattern p = Pattern.compile("\t|\r|\n");
			Matcher m = p.matcher(str);
			dest = m.replaceAll("");
		}
		return dest;
	}

	public static String GenerateOrderMessage(Tborderhead head, List<Tborderlist> items) {
		OrderXmlModel model = new OrderXmlModel();
		model.MESSAGEHEAD = new MessageHead();
		model.MESSAGEHEAD.MESSAGEID = java.util.UUID.randomUUID().toString();
		model.MESSAGEHEAD.MESSAGETYPE = SystemConstants.Order_Message_Type;
		model.MESSAGEHEAD.RECEIVERID = SystemConstants.Receiver_ID;
		model.MESSAGEHEAD.SENDERID = SystemConstants.Sender_ID;
		model.MESSAGEHEAD.SENDTIME = df.format(new Date());
		model.MESSAGEHEAD.SEQNO = "22809";

		model.MESSAGEBODY = new OrderBody();
		OrderBodyMaster body_master = new OrderBodyMaster();
		OrderBodyDetail body_detail = new OrderBodyDetail();
		List<ORDERLIST> list = new ArrayList<ORDERLIST>();
		model.MESSAGEBODY.BODYMASTER = body_master;
		model.MESSAGEBODY.BODYDETAIL = body_detail;

		body_master.BILLMODE = head.getBillmode();
		body_master.CBECODE = head.getCbecode();
		body_master.CBECODEINSP = head.getCbecodeinsp();
		body_master.CBENAME = head.getCbename();
		body_master.CHARGINGTYPE = head.getChargetype();
		body_master.COIN = head.getCoin();
		body_master.COLLECTIONUSERADDRESS = head.getCollectionuseraddress();
		body_master.COLLECTIONUSERNAME = head.getCollectionusername();
		body_master.DECLCODE = head.getDeclcode();
		body_master.DECLNAME = head.getDeclname();
		body_master.ECPCODE = head.getEcpcode();
		body_master.ECPNAME = head.getEcpname();
		body_master.EXTENDFIELD3 = head.getExtendfieid3();
		body_master.EXTENDFIELD4 = head.getExtendfieid4();
		body_master.EXTENDFIELD5 = head.getExtendfieid5();
		body_master.ORDERSUM = head.getOrdersum().toString();
		body_master.GOODSVALUE = head.getOrdersum().toString();
		body_master.ORDERID = head.getExpressnumber().replace("LVS", "");
		// 发货人所在国（海关代码
		body_master.SENDERUSERCOUNTRY = head.getSendusercountry();
		// 发货人名称
		body_master.SHIPPER = head.getSendusername();
		body_master.IETYPE = head.getIetype();
		body_master.MODIFYMARK = head.getModifymark();
		if (head.getSubmittime() != null) {
			body_master.SUBMITTIME = df.format(head.getSubmittime());
		}
		body_master.SENDUSERCOUNTRYINSP = head.getSendusercountryinsp();
		body_master.PAYNUMBER = head.getPaynumber();
		body_master.LICENSE_NO = head.getLicenseno();
		/// 国检总局报关企业备案号
		body_master.INSPDECLCODE = head.getInspdeclarecode();
		/// 收货人国家（国检编码）
		body_master.COLLECTIONUSERCOUNTRYINSP = head.getCollusercountryinsp();
		/// 发货人所在国（国检编码）
		body_master.SENDERUSERCOUNTRYINSP = head.getSenderusercountryinsp();
		/// 国检总局物流企业备案号
		body_master.WLQYCODEINSP = head.getWlqycodeinsp();
		/// 物流企业名称（国检）
		body_master.DELIVERYENTERPRISENAME = head.getDeliverenterprisename();
		/// 优惠减免金额(国检) 有值就填，无值默认0
		body_master.DISCOUNT = head.getDiscount().toString();
		/// 订单商品运费（国检）有值就填，无值默认0
		body_master.FREIGHT = head.getFreight().toString();
		/// 进出口标志（国检）
		body_master.I_E_FLAG = head.getIeflag();
		/// 电商平台名称
		body_master.ECPNAME = head.getEcpname();
		// 国检总局电商平台备案号
		body_master.INSPECPCODE = head.getEcpcodeinsp();
		// 国检总局电商企业备案号
		body_master.INSPCBECODE = head.getCbecodeinsp();
		body_master.COININSP = head.getCoinInsp();
		// 收货人国家海关编码
		body_master.COLLECTIONUSERCOUNTRY = head.getCollectionCountryCus();
		if (items != null) {
			for (Tborderlist detail : items) {
				ORDERLIST order_list = new ORDERLIST();
				order_list.AMOUNT = detail.getAmount().toString();
				order_list.AMOUNT1 = detail.getAmount1().toString();
				order_list.COIN = detail.getCoin();
				order_list.COININSP = detail.getCoininsp();
				order_list.FLAG = detail.getFlag();
				order_list.GOODID = detail.getGoodid();
				order_list.GOODNAME = detail.getGoodname();
				java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");
				order_list.GOODPRICE = df.format(detail.getGoodprice());
				order_list.NETWEIGHT = detail.getNetweight().toString();
				order_list.ORDERSUM = df.format(detail.getOrdersum());
				order_list.SHELFGOODSNAME = detail.getShelfgoodsname();
				order_list.SPECIFICATIONS = detail.getSpecifications();
				order_list.SRCCOUNTRYINSP = detail.getSrccountryinsp();
				order_list.UNIT = detail.getUnit();
				order_list.UNIT1 = detail.getUnit1();
				order_list.UNITINSP = detail.getUnitinsp();
				order_list.SEQ_NO = detail.getSeqno().toString();
				order_list.COMM_BARCODE = "无";
				order_list.HS_CODE = detail.getHscode();
				order_list.HSCODE = detail.getHscode();
				order_list.COUNTRY_OF_DESTINATION = detail.getCountryofdestination();
				order_list.PRODUCT_RECORD_NO = detail.getProductrecordno();
				list.add(order_list);
			}
		}
		body_detail.list = list;
		XStream xStream = new XStream(new StaxDriver(new XmlFriendlyNameCoder("_-", "_")));
		xStream.alias("CBECMESSAGE", OrderXmlModel.class);
		xStream.alias("ORDERLIST", ORDERLIST.class);
		xStream.addImplicitCollection(OrderBodyDetail.class, "list");
		String xml = xStream.toXML(model);
		xml = replaceBlank(xml);
		return xml;
	}

	public static String GenerateExpressMessage(Tbwaybill bill) {
		WaybillXmlModel model = new WaybillXmlModel();
		model.MESSAGEHEAD = new MessageHead();
		model.MESSAGEHEAD.MESSAGEID = java.util.UUID.randomUUID().toString();
		model.MESSAGEHEAD.MESSAGETYPE = SystemConstants.Waybill_Message_Type;
		model.MESSAGEHEAD.RECEIVERID = SystemConstants.Receiver_ID;
		model.MESSAGEHEAD.SENDERID = SystemConstants.Sender_ID;
		model.MESSAGEHEAD.SENDTIME = df.format(new Date());
		model.MESSAGEHEAD.SEQNO = "22809";

		model.MESSAGEBODY = new WaybillBody();
		WaybillBodyMaster body_master = new WaybillBodyMaster();
		body_master.BILLNO = bill.getBillNo();
		body_master.BILLMODE = bill.getBillMode();
		body_master.AMOUNT = bill.getAmount().toString();
		body_master.APPLYPORTINSP = bill.getApplyPortInsp();
		body_master.BATCHNUMBER = bill.getTotalTransferNumber();
		body_master.BILLMODE = bill.getBillMode();
		body_master.CBECODE = bill.getCbeCode();
		body_master.CBECODEINSP = bill.getCbeCodeInsp();
		body_master.CBENAME = bill.getCbeName();
		body_master.COININSP = bill.getCoinInsp();
		body_master.COLLECTIONUSERADDRESS = bill.getCollectionUserAddress();
		body_master.COLLECTIONUSERCOUNTRY = bill.getCollectionUserCountry();
		body_master.COLLECTIONUSERCOUNTRYINSP = bill.getCollectionUserCountryInsp();
		body_master.COLLECTIONUSERNAME = bill.getCollectionUserName();
		body_master.COLLECTIONUSERTELEPHONE = bill.getCollectionUserTelephone();
		body_master.CROSSFREIGHT = bill.getCrossFreight().toString();
		body_master.CUSTOMERID = bill.getCustomerId();
		body_master.DECLAREDATE = df.format(bill.getDeclareDate());
		body_master.DECLAREPORT = bill.getDeclarePort();
		body_master.DELIVERYENTERPRISECODE = bill.getDeliverEnterpriseCode();
		body_master.DELIVERYENTERPRISENAME = bill.getDeliverEnterpriseName();
		body_master.DESTINATIONPORT = bill.getDestinationPort();
		body_master.ECPCODE = bill.getEcpCode();
		body_master.ECPNAME = bill.getEcpName();
		body_master.FREIGHT = bill.getFreight().toString();
		body_master.IDTYPE = bill.getIdType();
		body_master.IETYPE = bill.getIeType();
		body_master.JCBORDERPORT = bill.getJcbOrderPort();
		body_master.JCBORDERPORTINSP = bill.getJcbOrderOrPortInsp();
		body_master.I_E_TIME = df.format(bill.getJcbOrderTime());
		body_master.MODIFYMARK = bill.getModifyMask();
		body_master.NETWEIGHT = bill.getNetWeight().toString();
		body_master.ORDERID = bill.getOrderId().replaceFirst("LVS", "");
		body_master.PACKCATEGORY = bill.getPackageCategory();
		body_master.PACKCATEGORYINSP = bill.getPackCategoryInsp();
		body_master.PACKNUM = bill.getPackNum().toString();
		body_master.REMARK = bill.getRemark();
		body_master.SENDERUSERADDRESS = bill.getSenderAddress();
		body_master.SENDERUSERCOUNTRY = bill.getSenderCountry();
		body_master.SHIPPER = bill.getSenderName();
		body_master.SHIPPER = "河南龙库供应链管理有限公司";
		body_master.SENDERUSERTELEPHONE = bill.getSenderTelephone();
		body_master.SHIPCODEINSP = bill.getShipCodeInsp();
		body_master.SHIPNAME = bill.getShipName();
		body_master.SHIPNAMEINSP = bill.getShipNameInsp();
		body_master.TRACKNO = bill.getTrackNo();
		body_master.TRACKSTATUS = bill.getTrackStatus();
		body_master.TRADECOUNTRY = bill.getTradeCountry();
		// 运单号
		body_master.TRANSFERNUMBER = bill.getTarnsferNumber();
		body_master.TRANSFERREGIONINSP = bill.getTransferRegionInsp();
		body_master.TRANSFERTYPE = bill.getTransferType();
		body_master.TRANSFERTYPEINSP = bill.getTransferTypeInsp();
		body_master.WEIGHT = bill.getWeight().toString();
		body_master.WLQYCODEINSP = bill.getLogisticsCodeInsp();
		body_master.COLLECTIONUSERCOUNTRYINSP = bill.getCollectionUserCountryInsp();
		// 运单提交日期
		body_master.SUBMITTIME = df.format(bill.getSubmitTime());
		// 价值外币（国检）
		java.text.DecimalFormat decimal_format = new java.text.DecimalFormat("#.00");
		body_master.TOTALVALUE = decimal_format.format(bill.getTotalValue());
		/// 抵运港（国检）
		body_master.ARRIVED_PORT = bill.getArrivedPort();
		// 监管机构代码(国检)
		body_master.REGULATORCODE = bill.getRegulatorcode();
		// 监管机构名称（国检）
		body_master.REGULATORNAME = bill.getRegulatorname();
		/// 进出口标志（国检）
		body_master.IN_OUT_FLAG = bill.getInOutFlag();
		// 进出口模式（国检）
		body_master.IMPORT_TYPE = bill.getImportType();
		/// 码头/货场代码（国检）
		body_master.GOODS_YARD_CODE = bill.getGoodsYardCode();
		// 发货人城市(国检)
		body_master.SHIPPERCITY = bill.getShipperCity();
		// 发货人国家（国检代码）
		body_master.INSPSHIPPERCOUNTRY = bill.getShipperCountryInsp();
		// 装运港/指运港（国检）
		body_master.INSPDESTINATIONPORT = bill.getIsnpDestinationPort();
		// 运输工具代码（海关）
		body_master.SHIPCODE = bill.getShipCode();
		// 起运国/抵运国（国检）
		body_master.INSPCOUNTRYCODE = bill.getInspCountryCode();
		// 起运国/运抵国（海关）
		body_master.COUNTRYCODE = bill.getDestinationCountryCus();
		// 商品名称
		body_master.GOODNAME = bill.getGoodsName();
		body_master.JCBORDERPORTINSP = "41018406";
		body_master.ARRIVED_PORT = "554003";
		body_master.GOODS_YARD_CODE = "994102";
		body_master.REGULATORNAME = "郑州综合保税区局本部";
		body_master.INSPDESTINATIONPORT = "554003";
		body_master.INSPCOUNTRYCODE = "554";
		model.MESSAGEBODY.BODYMASTER = body_master;
		XStream xStream = new XStream(new StaxDriver(new XmlFriendlyNameCoder("_-", "_")));
		xStream.alias("CBECMESSAGE", WaybillXmlModel.class);
		// String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>
		// \n";
		String xml = xStream.toXML(model);
		return xml;
	}

	public static String GeneratePayMessage(Tbpayinfo _pay) {
		PayXmlModel model = new PayXmlModel();
		model.MESSAGEHEAD = new PayMessageHeader();
		model.MESSAGEHEAD.MESSAGEID = java.util.UUID.randomUUID().toString();
		model.MESSAGEHEAD.MESSAGETYPE = SystemConstants.Pay_Message_Type;
		model.MESSAGEHEAD.RECEIVERID = SystemConstants.Receiver_ID;
		model.MESSAGEHEAD.SENDERID = SystemConstants.Sender_ID;
		model.MESSAGEHEAD.SENDTIME = df.format(new Date());

		model.MESSAGEBODY = new PayBody();
		PayBodyMaster body_master = new PayBodyMaster();
		model.MESSAGEBODY.BODYMASTER = body_master;
		body_master.SEQNO = "22809";
		body_master.BILLMODE = _pay.getBillmode();
		body_master.CBECODE = _pay.getCbecode();
		body_master.FEE = _pay.getFee().toString();
		body_master.IETYPE = _pay.getIetype();
		body_master.MODIFYMARK = _pay.getModifymark();
		body_master.MONETARYTYPE = _pay.getMonetarytype();
		body_master.ORDERID = _pay.getOrderid().replaceFirst("LVS", "");
		body_master.PAYMENTTYPE = _pay.getPaymenttype();
		body_master.PAYTIME = df.format(_pay.getPaytime());
		body_master.PAYNUMBER = _pay.getGuid();
		body_master.REMARK = _pay.getRemark();
		body_master.INSPCBECODE = _pay.getInspCbeCode();
		XStream xStream = new XStream(new StaxDriver());
		xStream.alias("CBECMESSAGE", PayXmlModel.class);
		// String top="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>
		// \n";
		String xml = xStream.toXML(model);
		return xml;
	}

	public static String GenerateInventoryMessage(Tbpayinfo pay, Tbwaybill bill, Tborderhead head,
			List<Tborderlist> items) {
		InventoryXmlModel model = new InventoryXmlModel();
		model.MESSAGEHEAD = new MessageHead();
		model.MESSAGEHEAD.MESSAGEID = java.util.UUID.randomUUID().toString();
		model.MESSAGEHEAD.MESSAGETYPE = SystemConstants.Inventory_Message_Type;
		model.MESSAGEHEAD.RECEIVERID = SystemConstants.Receiver_ID;
		model.MESSAGEHEAD.SENDERID = SystemConstants.Sender_ID;
		model.MESSAGEHEAD.SENDTIME = df.format(new Date());
		model.MESSAGEHEAD.SEQNO = "22809";

		model.MESSAGEBODY = new InventoryBody();
		InventoryBodyMaster body_master = new InventoryBodyMaster();
		model.MESSAGEBODY.BODYMASTER = body_master;
		// 抵运港代码（国检）
		body_master.ARRIVED_PORT = bill.getArrivedPort();
		// 抵运港名称（国检）
		body_master.ARRIVED_PORT_NAME = bill.getArrivedPortName();
		// 批次号
		body_master.BATCHNUMBER = head.getBatchnumber();
		// 模式编码（海关）
		body_master.BILLMODE = head.getBillmode();
		// 海关清单号
		body_master.CBECBILLNO = "";
		body_master.CBECODE = head.getCbecode();
		body_master.CBENAME = head.getCbename();
		body_master.CHARGINGTYPE = head.getChargetype();
		body_master.COLLECTIONUSERCOUNTRYINSP = bill.getCollectionUserCountryInsp();
		body_master.COLLECTIONUSERTEL = bill.getCollectionUserTelephone();
		body_master.CONSIGNEE = bill.getCollectionUserName();
		body_master.CONSIGNEEADDRESS = bill.getCollectionUserAddress();
		// 收货人国家（海关编码）
		body_master.CONSIGNEECOUNTRY = bill.getCollectionUserCountry();
		// 发货人地址（国检）
		body_master.CONSIGNOR_ADDR = bill.getSenderAddress();
		body_master.CONSIGNOR_TEL = bill.getSenderTelephone();
		// 申报人姓名,必填
		body_master.CONTACT = "";
		// 币制，海关代码
		body_master.CURRENCY = pay.getMonetarytype();
		// 申报口岸，海关
		body_master.DECLAREPORT = bill.getDeclarePort();
		// 申报口岸（国检）
		body_master.DECLAREPORTNAME = bill.getJcbOrderPort();
		// 申报口岸（海关）
		body_master.DECLCODE = bill.getDeclarePort();
		// 报关企业名称
		body_master.DECLNAME = head.getDeclname();
		// 申报人联系电话
		body_master.DECLTEL = "";
		body_master.DESTINATIONPORT = bill.getDestinationPort();
		body_master.GUID = java.util.UUID.randomUUID().toString();
		body_master.I_E_TIME = df.format(bill.getiETime());
		// 进出境口岸(海关)
		body_master.IEPORT = bill.getJcbOrderPort();
		// 进出口类型（海关）：I 进口；E 出口
		body_master.IETYPE = "E";
		// 进出口模式（国检）,0一般，1包税
		body_master.IMPORT_TYPE = "0";
		// 进出口标志（国检）I 进口 O 出口 A 进出口
		body_master.IN_OUT_FLAG = "O";
		// 清单号
		body_master.INSPBILLNO = "";
		// 国检总局电商企业编号
		body_master.INSPCODE = head.getEcpcodeinsp();
		// 起运国/运抵国（国检代码）
		// body_master.INSPCOUNTRYCODE = bill.getInspCountryCode;
		// 起运国/运抵国（国检名称）
		// body_master.INSPCOUNTRYNAME=bill.getInspCountryName;
		// 外币币制(国检)
		// body_master.INSPCURRENCY
		XStream xStream = new XStream(new StaxDriver(new XmlFriendlyNameCoder("_-", "_")));
		String xml = xStream.toXML(model);
		return xml;
	}

	public static String GenerateInventoryMessage(TbInventoryHead inventory_head,
			List<TbInventoryBody> inventory_bodies) {
		InventoryXmlModel model = new InventoryXmlModel();
		model.MESSAGEHEAD = new MessageHead();
		model.MESSAGEHEAD.MESSAGEID = java.util.UUID.randomUUID().toString();
		model.MESSAGEHEAD.MESSAGETYPE = SystemConstants.Inventory_Message_Type;
		model.MESSAGEHEAD.RECEIVERID = SystemConstants.Receiver_ID;
		model.MESSAGEHEAD.SENDERID = SystemConstants.Sender_ID;
		model.MESSAGEHEAD.SENDTIME = df.format(new Date());
		model.MESSAGEHEAD.SEQNO = "22809";
		model.MESSAGEBODY = new InventoryBody();
		InventoryBodyMaster body_master = new InventoryBodyMaster();
		model.MESSAGEBODY.BODYMASTER = body_master;
		body_master.ARRIVED_PORT = inventory_head.getArrivedPort();
		body_master.ARRIVED_PORT_NAME = inventory_head.getArrivedPortName();
		body_master.BATCHNUMBER = inventory_head.getBatchNumber();
		body_master.BILLMODE = inventory_head.getBillMode();
		body_master.CBECBILLNO = inventory_head.getCbeCbillNo();
		body_master.CBECODE = inventory_head.getCbeCode();
		body_master.CBENAME = inventory_head.getCbeName();
		body_master.CHARGINGTYPE = inventory_head.getChargingType();
		body_master.COLLECTIONUSERCOUNTRYINSP = inventory_head.getCollectionUserCountryInsp();
		body_master.COLLECTIONUSERTEL = inventory_head.getCollectionUserTel();
		body_master.CONSIGNEE = inventory_head.getConsignee();
		body_master.CONSIGNEEADDRESS = inventory_head.getConsigneeAddress();
		body_master.CONSIGNEECOUNTRY = inventory_head.getConsigneeCountry();
		body_master.CONSIGNOR_ADDR = inventory_head.getConsignorAddr();
		body_master.CONSIGNOR_TEL = inventory_head.getConsignorTel();
		body_master.CONTACT = inventory_head.getContact();
		body_master.COUNTRYCODE = inventory_head.getCountryCode();
		body_master.CURRENCY = inventory_head.getCurrency();
		body_master.CURRENCYNAME = inventory_head.getCurrencyName();
		body_master.DECLAREPORT = inventory_head.getDeclarePort();
		body_master.DECLAREPORTINSP = inventory_head.getDeclarePortInsp();
		body_master.DECLAREPORTNAME = inventory_head.getDeclarePortNameInsp();
		body_master.DECLCODE = inventory_head.getDeclCode();
		body_master.DECLNAME = inventory_head.getDeclName();
		body_master.DECLTEL = inventory_head.getDeclTel();
		body_master.DESTINATIONPORT = inventory_head.getDestinationPort();
		body_master.ECPCODE = inventory_head.getEcpCode();
		body_master.ECPNAME = inventory_head.getEcpName();
		body_master.ENTRY_LIST_NUMBER = inventory_head.getEntryListNumber();
		body_master.GUID = inventory_head.getGuid();
		body_master.I_E_TIME = df.format(inventory_head.getiETime());
		body_master.IEPORT = inventory_head.getIePort();
		body_master.IETYPE = inventory_head.getIeType();
		body_master.IMPORT_TYPE = inventory_head.getImportType().toString();
		body_master.IN_OUT_FLAG = inventory_head.getInOutFlag();
		body_master.INSPBILLNO = inventory_head.getInspBillNo();
		body_master.INSPCODE = inventory_head.getInspCode();
		body_master.INSPCOUNTRYCODE = inventory_head.getInspCountryCode();
		body_master.INSPCOUNTRYNAME = inventory_head.getInspCountryName();
		body_master.INSPCURRENCY = inventory_head.getCurrencyInsp();
		body_master.INSPDECLCODE = inventory_head.getInspDeclCode();
		body_master.INSPDESTINATIONPORT = inventory_head.getDestinationPortInsp();
		body_master.INSPECPCODE = inventory_head.getInspEcpCode();
		body_master.INSPIEPORT = inventory_head.getIsnpIePort();
		body_master.INSPLOGISTICSCODE = inventory_head.getInspLogisticsCode();
		body_master.INSPPAYECODE = inventory_head.getInspPayCode();
		// body_master.INSPSHIPPERCOUNTRY=inventory_head.getship
		body_master.INSPTRAFWAY = inventory_head.getInspTrafWay();
		body_master.LIST_TYPE = inventory_head.getListType();
		body_master.LOGISTICSCODE = inventory_head.getLogisticsCode();
		body_master.LOGISTICSNAME = inventory_head.getLogisticsName();
		body_master.MODIFYMARK = inventory_head.getModifymark();
		body_master.NETWEIGHT = inventory_head.getNetWeight().toString();
		body_master.ORDERNO = inventory_head.getOrderNo();
		body_master.PACKCATEGORY = inventory_head.getPackCategory();
		body_master.PACKCATEGORYINSP = inventory_head.getPackCategoryInsp();
		body_master.PACKNUMBER = inventory_head.getPackNumber().toString();
		body_master.PAYECODE = inventory_head.getPayCode();
		body_master.PAYNUMBER = inventory_head.getPayNumber();
		body_master.REGULATORCODE = inventory_head.getRegulatorCode();
		body_master.REGULATORCODE = "410900";
		body_master.REGULATORNAME = inventory_head.getRegulatorName();
		body_master.REMARK = inventory_head.getRemark();
		body_master.SHIPCODE = inventory_head.getShipCode();
		body_master.SHIPCODEINSP = inventory_head.getShipCodeInsp();
		body_master.SHIPNAME = inventory_head.getShipName();
		body_master.SHIPPER = inventory_head.getShipper();
		body_master.SHIPPERCITY = inventory_head.getShipperCity();
		body_master.SHIPPERCOUNTRY = inventory_head.getShipperCountry();
		body_master.SUBMITTIME = df.format(inventory_head.getSubmitTime());
		body_master.TOTALNUMBER = inventory_head.getTotalNumber();
		java.text.DecimalFormat decimal_format = new java.text.DecimalFormat("#.00");
		body_master.TOTALVALUE = decimal_format.format(inventory_head.getTotalValue());
		body_master.TOTALVALUERMB = decimal_format.format(inventory_head.getTotalValueRmb());
		body_master.TRADE_MODE = inventory_head.getTradeMode();
		body_master.TRAFWAY = inventory_head.getTrafWay();
		body_master.TRANSFERNUMBER = inventory_head.getTransferNumber();
		body_master.WEIGHT = inventory_head.getNetWeight().toString();
		InventoryBodyDetail detail = new InventoryBodyDetail();
		model.MESSAGEBODY.BODYDETAIL = detail;
		detail.list = new ArrayList<InventoryGoods>();
		for (TbInventoryBody body : inventory_bodies) {
			InventoryGoods goods = new InventoryGoods();
			goods.AMOUNT = String.valueOf(body.getAmount().intValue());
			goods.AMOUNT1 = String.valueOf(body.getAmount1());
			goods.BRAND = body.getBrand();
			goods.COMM_BARCODE = body.getCommBarCode();
			goods.COUNTRY_OF_DESTINATION = body.getCountryOfDestination();
			goods.CURRENCY = body.getCurrency();
			goods.DELIVERYNUMBER = body.getDeliveryNumber();
			goods.ENTRY_LIST_NUMBER = body.getEntryListNumber();
			goods.GOODSMODEL = body.getGoodsModel();
			goods.GOODSNO = body.getGoodsNo();
			goods.GOODSNAME = body.getGoodsName();
			goods.HS_CODE = body.getHsCode();
			goods.HSCODE = body.getHsCode();
			goods.INSPCOMMODITYNUMBER = body.getCommodityNumberInsp();
			goods.NETWEIGHT = body.getNetWeight().toString();
			goods.ORDERSUM = body.getOrderSum().toString();
			goods.PRICE = body.getPrice().toString();
			goods.SEQ_NO = body.getSeqNo().toString();
			goods.SHELFGOODSNAME = body.getShelfGoodsName();
			goods.SRCCOUNTRY = body.getSrcCountry();
			goods.SRCCOUNTRYINSP = body.getSrcCountryInsp();
			goods.SRCCOUNTRYINSPNAME = body.getSrcCountryNameInsp();
			goods.UNIT = body.getUnit();
			goods.UNIT1 = body.getUnit1();
			goods.UNIT2 = body.getUnit2();
			goods.UNITNAME = body.getUnitName();
			goods.WEIGHT = body.getWeight().toString();
			detail.list.add(goods);
		}
		XStream xStream = new XStream(new StaxDriver(new XmlFriendlyNameCoder("_-", "_")));
		xStream.alias("GOODS", InventoryGoods.class);
		xStream.alias("CBECMESSAGE", InventoryXmlModel.class);
		xStream.addImplicitCollection(InventoryBodyDetail.class, "list");
		String xml = xStream.toXML(model);
		return xml;
	}
}
